package com.wms.controller;

import com.wms.common.Result;
import com.wms.entity.Storageentry;
import com.wms.service.StorageentryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/storageentry")
public class StorageentryController {

    @Autowired
    private StorageentryService storageentryService;

    // 获取所有进口订单
    @GetMapping("/list")
    public Result<List<Storageentry>> list() {
        List<Storageentry> storageentries = storageentryService.list();
        return Result.suc("获取成功", storageentries);
    }

    // 根据ID获取进口订单信息
    @GetMapping("/{id}")
    public Result<Storageentry> getById(@PathVariable Integer id) {
        Storageentry storageentry = storageentryService.getById(id);
        if (storageentry != null) {
            return Result.suc("获取成功", storageentry);
        } else {
            return Result.fail("进口订单不存在");
        }
    }

    // 新增进口订单
    @PostMapping("/add")
    public Result<?> add(@RequestBody Storageentry storageentry) {
        boolean saveSuccess = storageentryService.save(storageentry);
        if (saveSuccess) {
            return Result.suc("新增成功");
        } else {
            return Result.fail("新增失败");
        }
    }

    // 更新进口订单信息
    @PutMapping("/update")
    public Result<?> update(@RequestBody Storageentry storageentry) {
        boolean updateSuccess = storageentryService.updateById(storageentry);
        if (updateSuccess) {
            return Result.suc("更新成功");
        } else {
            return Result.fail("更新失败");
        }
    }

    // 删除进口订单
    @DeleteMapping("/delete/{id}")
    public Result<?> delete(@PathVariable Integer id) {
        boolean removeSuccess = storageentryService.removeById(id);
        if (removeSuccess) {
            return Result.suc("删除成功");
        } else {
            return Result.fail("删除失败");
        }
    }
}
